package cn.tx.controller;

import cn.tx.constant.MessageConstant;
import cn.tx.entity.PageResult;
import cn.tx.entity.QueryPageBean;
import cn.tx.entity.Result;
import cn.tx.pojo.Setmeal;
import cn.tx.service.SetmealService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Snake Eyes
 * @PROJECT_NAME: health_parent
 * @DESCRIPTION:
 * @USER: 11647
 * @DATE: 2021/8/28 21:08
 * @Email: 1164763541@qq.com
 */
@RestController
@RequestMapping("setmeal")

public class SetmealController {
    @Reference
    private SetmealService setmealService;

    /**
     * @return
     * @author :11647
     * @date ：Created in 2021/8/29  16:00
     * @description：(描述) 分页查询
     * @modified By：11647
     * @version:
     */
    @RequestMapping("findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean pageBean) {
        PageResult page = setmealService.findPage(pageBean);
        return new PageResult(page.getTotal(), page.getRows());
    }

    /**
     * @return
     * @author :11647
     * @date ：Created in 2021/8/29  16:00
     * @description：(描述)查询所有
     * @modified By：11647
     * @version:
     */
    @RequestMapping("findAll.do")
    public Result findAll() {
        try {
            List<Setmeal> page = setmealService.findAll();
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, page);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    @RequestMapping("save.do")
    public Result save(Integer[] checkgroupIds, @RequestBody Setmeal setmeal) {

        try {
            setmealService.save(setmeal, checkgroupIds);
            return new Result(true, MessageConstant.ADD_SETMEAL_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_SETMEAL_FAIL);
        }
    }

    /**
     * @return
     * @author :11647
     * @date ：Created in 2021/8/31  13:13
     * @description：(描述) 查询所有当前套餐包含的检查组
     * @modified By：11647
     * @version:
     */
    @RequestMapping("findById")
    public Result findById(Integer setmealid) {
        try {
            Integer[] ids = setmealService.findIntTableId(setmealid);
            return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS, ids);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.QUERY_CHECKGROUP_FAIL);
        }
    }

    /**
     * @return
     * @author :11647
     * @date ：Created in 2021/8/31  15:15
     * @description：(描述) 修改方法
     * @modified By：11647
     * @version:
     */
    @RequestMapping("update.do")
    public Result update(Integer[] checkgroupIds, @RequestBody Setmeal setmeal) {
        try {
            setmealService.update(checkgroupIds,setmeal);
            return new Result(true, MessageConstant.EDIT_CHECKGROUP_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_CHECKGROUP_FAIL);
        }
    }

    /**
     * @return
     * @author :11647
     * @date ：Created in 2021/8/31  15:14
     * @description：(描述) 删除方法
     * @modified By：11647
     * @version:
     */
    @RequestMapping("delete.do")
    public Result delete(@RequestBody Setmeal setmeal) {
        try {
            setmealService.delete(setmeal.getId());
            return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.DELETE_CHECKGROUP_FAIL);

        }
    }



}
